package org.example.autosuggest;

import com.vmware.antlr4c3.CodeCompletionCore;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.tree.ParseTree;

import java.util.List;

public class C3WithMysql {
    public static void main(String[] args) {
        CharStream input = CharStreams.fromString("Create table abc ");
        com.neuronbit.parser.MySqlLexer lexer = new com.neuronbit.parser.MySqlLexer(input);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        com.neuronbit.parser.MySqlParser parser = new com.neuronbit.parser.MySqlParser(tokens);

        parser.setErrorHandler(new DefaultErrorStrategy(){
            @Override
            protected void reportNoViableAlternative(Parser recognizer, NoViableAltException e) {
                super.reportNoViableAlternative(recognizer, e);
            }
        });

        ParseTree root = parser.root();

        CodeCompletionCore c3 = new CodeCompletionCore(parser, null, null);

        CodeCompletionCore.CandidatesCollection candidates = c3.collectCandidates(0, null);
        for (List<Integer> value : candidates.tokens.values()) {
            if (null != value && value.size() > 0) {
                System.out.println(parser.getVocabulary().getSymbolicName(value.get(0)));
            }
        }
//        MysqlSqlDefaultListener listener = new MysqlSqlDefaultListener();
//
//        ParseTreeWalker walker = new ParseTreeWalker(); // create standard walker
//        walker.walk(listener, root);
//
//        SqlCreateTable table = listener.getTable();
    }
}
